﻿using Lilium.Unity.Adapters;
using Lilium.Unity.ContainerConfiguration;
using Lilium.Unity.LifetimeManagers;
using Lilium.Web.Mvc;
using Lilium.Web.Mvc.Context;
using Lilium.Web.Mvc.EntityFilters;
using Lilium.Web.Mvc.Metadata;
using Lilium.Web.Mvc.State;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.ObjectBuilder;


namespace Lilium.Unity.MvcHttpApplication
{
    public sealed class MvcHttpApplicationExtension : UnityContainerExtension
	{
		protected override void Initialize()
		{
            // не помню, что это
            Container.EnsureExtension<ConfigurationReflectionExtension>();
			Context.BuildPlanStrategies.AddNew<EntityFilterConfigurationStrategy>(UnityBuildStage.PreCreation);
			Context.Policies.SetDefault<IEntityFilterConfigurationPolicy>(new EntityFilterReflectionPolicy(Container));

            Container
                .RegisterType<IMetadataService, MetadataService>(new PerRequestLifetimeManager())
                .RegisterType<IFilteringService, FilteringService>(new PerRequestLifetimeManager())
                .RegisterType<IStateService, TempDataStateService>(new PerRequestLifetimeManager())
                .RegisterType<IEntityWorkflowFactory, UnityWorkflowFactory>(new PerRequestLifetimeManager())
                .RegisterType<IActionContextService, ActionContextService>(new PerRequestLifetimeManager())
                            // Entity filters
                .RegisterType(typeof(Pager<>), new PerRequestLifetimeManager())
                .RegisterType(typeof(Alphabet<>), new PerRequestLifetimeManager())
                            // Selt registration
                .RegisterInstance<Lilium.IServiceProvider>(new ToServiceProvider(Container));

		}
	}
}
